package leetcode.slidwidow;

public class Lc3095 {


    public int minimumSubarrayLength(int[] nums, int k) {
        int ans = Integer.MAX_VALUE;
        int res = 0;
        int i = 0, j = 0;
        for (; j < nums.length; j++) {
            res |= nums[j];
            if (res >= k) {
                ans = Math.min(ans, j - i + 1);
                for (int l = j, tmp = 0; l >= i ; l--) {
                    tmp |= nums[l];
                    if (tmp >= k) {
                        ans = Math.min(ans, j - l + 1);
                        i = l + 1;
                        break;
                    }
                }
                res = getORAns(i, j, nums);
            }

        }
        return ans == Integer.MAX_VALUE ? -1 : ans;
    }
    int getORAns(int start, int end, int[] nums) {
        int ans = 0;
        for (int i = start; i <= end; i++) {
            ans |= nums[i];
        }
        return ans;
    }

    public static void main(String[] args) {
        Lc3095 lc3095 = new Lc3095();
        int[] a = {1,2};
        int k = 10;
        System.out.println(lc3095.minimumSubarrayLength(a, k));
        System.out.println(0|1);
    }

}
